function StandMenu()

	inventory = {}
	stand = {}
	icon = {}
	price = {}

	for k,v in pairs(plydata.inventory) do

	inventory[k] = v

	end

	for k,v in pairs(inventory) do

	stand[k] = 0

	end
	
	for k,v in pairs(inventory) do

	price[k] = 0

	end
	
	local function AddStand(k,v)

	local model = GetIModel(k)
	local skin = GetISkin(k)

	icon["stand_" .. k] = vgui.Create( "SpawnIcon" )
	icon["stand_" .. k]:SetModel( model,skin )
	icon["stand_" .. k]:SetIconSize( 50, 50 )
	icon["stand_" .. k]:SetSize(50,50)
	icon["stand_" .. k]:SetPos(0,0)
	icon["stand_" .. k]:SetToolTip(v .. " "..GetIName(k) .. " - Price : " .. price[k])
	icon["stand_" .. k].DoClick = function()

	local itemmenu = DermaMenu()
	
	for x,y in pairs(Amounts) do
			
			if (y == "All") then y = stand[k] end
		
			if (y <= stand[k]) then
		
			itemmenu:AddOption("Remove " .. y .. " " .. GetIName(k),function()  
							
				if (y == stand[k]) then			
					Stand:RemoveItem(icon["stand_" .. k])				
				else				
					icon["stand_" .. k]:SetToolTip(stand[k] - y .. " " .. GetIName(k))				
				end
				
				stand[k] = stand[k] - y
				
				if (inventory[k] > 0) then				
					icon["inv_" .. k]:SetToolTip(inventory[k] + y .. " " .. GetIName(k))	
				else				
					AddInventory(k,y)				
				end
				
				inventory[k] = inventory[k] + y

			end )
			
		end
	
	end
	
	itemmenu:Open()
	
	end
	
	Stand:AddItem(icon["stand_" .. k])
	
end
	
	local function SetPrice(k,v)

	local PriceM = vgui.Create("DFrame")
	PriceM:SetPos(ScrW()/2 - 120,ScrH()/2 - 100)
	PriceM:SetSize(240, 200)
	PriceM:SetTitle("Set price of " .. GetIName(k))
	PriceM:SetDraggable(true)
	PriceM:ShowCloseButton(true)
	PriceM:SetVisible(true)
	PriceM:MakePopup()

	local Amount = vgui.Create( "DNumSlider", PriceM )
	Amount:SetPos( 20,40 )
	Amount:SetWide( 200 )
	Amount:SetText( "Amount" )
	Amount:SetMin( 1 )
	Amount:SetValue( 1 )
	Amount:SetMax( v )
	Amount:SetDecimals( 0 )
	
	local PriceL = vgui.Create("DLabel" , PriceM)
	PriceL:SetPos(20,80)
	PriceL:SetText("Price")
	PriceL:SetFont("BudgetLabel")
	PriceL:SizeToContents()

	local Price = vgui.Create("DTextEntry", PriceM)
	Price:SetText(1)
	Price:SetPos(20,100)
	Price:SetSize(200,20)

	Add = vgui.Create("DButton", PriceM)
	Add:SetPos(40,140)
	Add:SetSize(160,25)
	Add:SetText("Add " .. GetIName(k))
	Add.DoClick = function()

		local iprice = tonumber(Price:GetValue())
		local y = Amount:GetValue()
	
		if (iprice == nil or iprice == 0) then iprice = 1 end
	
		price[k] = iprice
		
		if (y == inventory[k]) then			
			Inventory:RemoveItem(icon["inv_" .. k])				
		else				
			icon["inv_" .. k]:SetToolTip(inventory[k] - y .. " " .. GetIName(k))				
		end
		
		inventory[k] = inventory[k] - y
		
		if (stand[k] > 0) then				
			icon["stand_" .. k]:SetToolTip(stand[k] + y .. " " .. GetIName(k) .. " - Price : " .. iprice)	
		else				
			AddStand(k,y)				
		end
		
		stand[k] = stand[k] + y
		
		PriceM:Close()
	
	end

end
	
	local function AddInventory(k,v)

		local model = GetIModel(k)
		local skin = GetISkin(k)

		icon["inv_" .. k] = vgui.Create( "SpawnIcon" )
		icon["inv_" .. k]:SetModel( model,skin )
		icon["inv_" .. k]:SetIconSize( 50, 50 )
		icon["inv_" .. k]:SetSize(50,50)
		icon["inv_" .. k]:SetPos(0,0)
		icon["inv_" .. k]:SetToolTip(v .. " "..GetIName(k))
		icon["inv_" .. k].DoClick = function()

		local itemmenu = DermaMenu()
		
		itemmenu:AddOption("Add " .. GetIName(k),function()  
							
		SetPrice(k,inventory[k])

		end )
		
		itemmenu:Open()
		
		end

		Inventory:AddItem(icon["inv_" .. k])	
		
	end

	Menu = vgui.Create("DFrame")
	Menu:SetPos(ScrW()/2 - 250,ScrH()/2 - 200)
	Menu:SetSize(500, 400)
	Menu:SetTitle("Stand Set Menu")
	Menu:SetDraggable(true)
	Menu:ShowCloseButton(true)
	Menu:SetVisible(true)
	Menu:MakePopup()

	Inventory = vgui.Create( "DPanelList" , Menu)
	Inventory:EnableVerticalScrollbar( true ) 
	Inventory:EnableHorizontal( true ) 
	Inventory:SetSpacing( 5 ) 
	Inventory:SetPadding( 5 )
	Inventory:SetPos(10,30)
	Inventory:SetSize(235,300)

	Stand = vgui.Create( "DPanelList" , Menu)
	Stand:EnableVerticalScrollbar( true ) 
	Stand:EnableHorizontal( true ) 
	Stand:SetSpacing( 5 ) 
	Stand:SetPadding( 5 )
	Stand:SetPos(255,30)
	Stand:SetSize(235,300)
	
	Text = vgui.Create("DTextEntry", Menu)
	Text:SetText("Selling goods")
	Text:SetPos(10,340)
	Text:SetSize(480,20)
	Text.OnTextChanged = function()
	
		local x = GetLength(Text:GetValue())
				
		if (x >= 100) then
			Text:SetText(string.sub(Text:GetValue(),1,100))
		end
	
	end
	
	SetUp = vgui.Create("DButton", Menu)
	SetUp:SetPos(190,370)
	SetUp:SetSize(120,20)
	SetUp:SetText("Set Up Market Stand")
	SetUp.DoClick = function()
	
	SetStandUp()
	Menu:Close()
	
	end

	for k,v in pairs(inventory) do

		if (v > 0) then


		AddInventory(k,v)
			
		
		end

	end	
	
end

function SetStandUp()

local data = {}
data.stand = {}
data.price = {}
data.text = Text:GetValue()

for k,v in pairs(stand) do

	if (v > 0) then
		data.stand[k] = v
	end

end

for k,v in pairs(price) do
	if (v > 0) then
		data.price[k] = v
	end
end

	
datastream.StreamToServer("standsetup",data)

end

function StandUmsg()

StandMenu()

end
usermessage.Hook("standmenu",StandUmsg)

function StandRemoveMenu()

	local Menu = vgui.Create("DFrame")
	Menu:SetPos(ScrW()/2 - 150,ScrH() - 200)
	Menu:SetSize(300, 80)
	Menu:SetTitle("")
	Menu:SetDraggable(true)
	Menu:ShowCloseButton(false)
	Menu:SetVisible(true)
	Menu:MakePopup()
	
	local Remove = vgui.Create("DButton", Menu)
	Remove:SetPos(40,40)
	Remove:SetSize(220,20)
	Remove:SetText("Remove Stand")
	Remove.DoClick = function()
	
		Menu:Remove()
		RunConsoleCommand("RemoveStandMenu")
	
	end

end
usermessage.Hook("standremovemenu",StandRemoveMenu)